//
//  PublicNavView.m
//  LOLBox
//
//  Created by mac on 15-3-26.
//  Copyright (c) 2015年 Honey. All rights reserved.
//

#import "PublicNavView.h"

@interface PublicNavView ()
{
    void (^_BBBlock)(NSString *, NSInteger);
}

@property (nonatomic, strong) NSArray *nameArr;
@property (nonatomic, strong) NSArray *atctionArr;

@end

@implementation PublicNavView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}


    
- (void)creatTheBtnAndIndex:(NSInteger)index
{
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    imgView.image = [UIImage imageNamed:@"bg_toolbar"];
    imgView.alpha = 0.8;
    [self addSubview:imgView];
    // 320 / 6
    /**
     *  导航条下面的导航
     */
    //NSArray *arr = @[@"最新",@"热评",@"官方",@"外服",@"赛事",@"攻略"];
    
    CGFloat length = self.frame.size.width / self.nameArr.count ;
    //NSLog(@"lenth:%f",length);
    for (NSInteger i = 0; i < self.nameArr.count; i++)
    {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(i * length, 5 - 2, length, 25 -2);
        btn.alpha = 0.9;
        //btn.backgroundColor = [UIColor grayColor];
        [btn setTitle:_nameArr[i] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor orangeColor] forState:UIControlStateHighlighted];
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [btn setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateSelected];
        btn.titleLabel.font = [UIFont systemFontOfSize:14];
        //[btn setBackgroundImage:[UIImage imageNamed:@"account_button"] forState:UIControlStateNormal];
        btn.tag = i + 10;
        [btn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];
        [btn setBackgroundImage:[UIImage imageNamed:@"sbar"] forState:UIControlStateSelected];
        if (i == index)
        {
            btn.selected = YES;
        }
        
        [self addSubview:btn];
    }
    
}


- (void)onClick:(UIButton *)btn
{
    
    for (NSInteger i = 0; i < 6; i++)
    {
        UIButton *bbj = (UIButton *)[self viewWithTag:10 + i];
        bbj.selected = NO;
    }
    btn.selected = YES;
    
    for (NSInteger j = 10 ; j < self.nameArr.count + 10; j++)
    {
        if (btn.tag == j) {
            _BBBlock(self.atctionArr[j - 10],j - 10);
        }
    }
}

- (void)changValue:(NSString *)str senderBlock:(void (^)(NSString *,NSInteger) )block
{
    
    _BBBlock = block;
}


//接收传来的值
- (void)senderValue:(NSArray *)nameArr andSecond:(NSArray *)ationArr
{
    self.nameArr = nameArr;
    self.atctionArr = ationArr;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
